import HttpClient, { HttpClientConfig, Method, RequestParams, ContentType } from "axios-mapper";
import networkConfig from "config/net.config";

const config: HttpClientConfig = {
	baseURL: networkConfig.baseUrl,
	headers: {
		token: "",
	},
};
interface HttpRequest {
	path?: string;
	method?: Method;
	params?: RequestParams;
	contentType?: ContentType;
	optionsSource?: HttpClientConfig;
}
class VAxios {
	private http: HttpClient;
	constructor(config: HttpClientConfig) {
		this.http = new HttpClient(config);
	}
	public request<T>(obj: HttpRequest): Promise<T | null> {
		return this.http.request<T>(obj.path, obj.method, obj.params, obj.contentType, obj.optionsSource);
	}
	public get<T>(obj: HttpRequest): Promise<T | null> {
		return this.http.request<T>(obj.path, Method.GET, obj.params, ContentType.form, obj.optionsSource);
	}
	public post<T>(obj: HttpRequest): Promise<T | null> {
		return this.http.request<T>(obj.path, Method.POST, obj.params, ContentType.json, obj.optionsSource);
	}
}

export default new VAxios(config);
